//
// Created by lijia on 2021/1/12.
//

#include "pwm.h"

static TIM_HandleTypeDef *tim;

void pwm_init(const TIM_HandleTypeDef *htim) {
	tim = (TIM_HandleTypeDef *) htim;
	HAL_TIM_PWM_Start(tim, TIM_CHANNEL_1);
	HAL_TIM_PWM_Start(tim, TIM_CHANNEL_2);
}

void pwm_set_ch1_counter(uint16_t v) {
	if (v <= PWM_MIN || v >= PWM_MAX) {
		return; // wel
	}
	__HAL_TIM_SET_COMPARE(tim, TIM_CHANNEL_1, v);
}

void pwm_set_ch2_counter(uint16_t v) {
	if (v <= PWM_MIN || v >= PWM_MAX) {
		return; // wel
	}
	__HAL_TIM_SET_COMPARE(tim, TIM_CHANNEL_2, v);
}
